import Index from "../pages/Index.vue";
import Team from "../pages/TeamPage.vue";
import User from "../pages/UserPage.vue";
import Search from "../pages/SearchPage.vue";
import UserEditPage from "../pages/UserEditPage.vue";
import {createRouter, createWebHistory} from "vue-router";
import SearchResultPage from "../pages/SearchResultPage.vue";
import UserLoginPage from "../pages/UserLoginPage.vue";

const routes = [
    {
        path: '/',
        component: Index,
        meta: { title: '首页' } // 添加元信息
    },
    {
        path: '/team',
        component: Team,
        meta: { title: '队伍' }
    },

    {
        path: '/user',
        component: User,
        meta: { title: '个人中心' }
    },
    {
        path: '/search',
        component: Search,
        meta: { title: '搜索' }
    },
    {
        path: '/user/edit',
        component: UserEditPage,
        meta: { title: '用户信息编辑' }
    },
    {
        path: '/user/list',
        component: SearchResultPage,
        meta: { title: '搜索结果页' }
    },
    {
        path: '/user/login',
        component: UserLoginPage,
        meta: { title: '用户登录' }
    }
];

const router = createRouter({
    history: createWebHistory(),
    routes // 确保这里使用的是定义好的 routes 数组
});

router.beforeEach((to) => {
    document.title = to.meta.title ? `${to.meta.title} - 伙伴匹配` : '伙伴匹配';
});

export default router;